package com.huaguoguo.huaguoguo.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
import org.springframework.http.server.reactive.ServerHttpResponse;
import reactor.core.publisher.Mono;

/**
 * 类说明： <br/>
 * author:huaguoguo
 * Date: 2019/2/26
 * Time: 23:23
 */
public class PostGatewayFilterFactory extends AbstractGatewayFilterFactory {
    private Logger logger = LoggerFactory.getLogger(PostGatewayFilterFactory.class);

    public GatewayFilter apply() {
        return apply(o -> {});
    }

    @Override
    public GatewayFilter apply(Object config) {
        return (exchange, chain) -> {
            logger.info("PostGatewayFilter...");
            return chain.filter(exchange).then(Mono.fromRunnable(() -> {
                ServerHttpResponse response = exchange.getResponse();
                //Manipulate the response in some way
            }));
        };
    }

}
